include $(top_dir)/helpers.mk

target ::= $(build_bot_dir)/scrapper
target_lib ::= $(build_bot_dir)/libscrapper.so
src_lib =
src_bin ::= main.c $(wildcard logging/*.c) $(src_lib)
obj_lib = $(patsubst %,$(build_bot_dir)/%,$(src_lib:.c=.o))
obj_bin := $(patsubst %,$(build_bot_dir)/%,$(src_bin:.c=.o))
build_dirs := $(call uniq, \
				$(addprefix $(build_bot_dir), $(dir $(src_bin))))

CFLAGS += -I$(telebot_include) -I$(zlog_include) -I$(bot_include)
LDFLAGS ::= -lpthread
LDLIBS ::= $(telebot_lib) $(zlog_lib)

all: $(build_dirs) $(target) lib

$(build_dirs):
	@mkdir -p $@

$(target): $(obj_bin)
	@$(call print_info,build scrapper bot)
	$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)

lib: $(target_lib)

$(target_lib): $(obj_lib)
	@$(call print_info,build scrapper shared library)
	$(CC) -shared -o $@ $(obj_lib) $(LDFLAGS) $(LDLIBS)

-include $(obj_bin:.o=.d)

$(obj_bin): $(build_bot_dir)/%.o: %.c
	$(CC) -c $(CFLAGS) $< -o $@

.PHONY: clean

clean:
	rm -fr $(target) $(target_lib) $(obj_bin) $(obj_bin:.o=.d)
